/*

This is example for SHT3X-DIS Digital Humidity & Temperature Sensors Arduino Library
ClosedCube SHT31-D [Digital I2C] Humidity and Temperature Sensor Breakout

Initial Date: 06-Oct-2015
Last Updated: 12-Oct-2016

Hardware connections for Arduino Uno:
VDD to 3.3V DC
SDA to A4
SCL to A5
GND to common ground

MIT License

*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include "ClosedCube_SHT31D.h"

ClosedCube_SHT31D sht3xd;

float TEM_Val = 0;
float HUM_Val = 0;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


void setup()
{
	//Wire.begin();

	Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  sht3xd.begin(0x44); // I2C address: 0x44 or 0x45
 
  display.clearDisplay();
  display.setTextSize(2);            
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(12,25);    
  display.println("67373UPUP");  
  display.display();
  delay(3000);
  
}

void oled_show()
  {
  display.clearDisplay();
  display.setTextSize(1);            
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(35,15);            
  display.println("TEM:");  
  display.setCursor(60,15);            
  display.println(TEM_Val);
  display.setCursor(35, 35);            
  display.println("HUM:");
  display.setCursor(60, 35);           
  display.println(HUM_Val);
  display.display();
  }
void loop()
{
	//printResult("ClockStrech Mode", sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_LOW, SHT3XD_MODE_CLOCK_STRETCH, 50));
  TEM_Val = sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_LOW, SHT3XD_MODE_CLOCK_STRETCH, 50).t;
	delay(250);
	//printResult("Pooling Mode", sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_HIGH, SHT3XD_MODE_POLLING, 50));
  HUM_Val = sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_LOW, SHT3XD_MODE_CLOCK_STRETCH, 50).rh;
	delay(250);
  oled_show();
  delay(500);
}
